<? include 'server_config.php'; 

if($_SESSION['user_idx'] == "")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}


$user_img = "./upload/member_photo/".$_SESSION['user_idx'];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
	<title> New Document </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="Stylesheet" type="text/css" href="./css/nddCommon.css" />
	<script type="text/javascript" src="./js/jquery-1.6.2.min.js"></script>

	<script type="text/javascript">
		dayName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"];
		second = 1000;
		minute = second * 60;
		hour = minute * 60;
		day = hour * 24;

		getTimestring = function(time) {

		var now = new Date();
		var diff = now - time;

		var dhour = Math.floor(diff / hour);
		diff -= dhour * hour;
		var dminute = Math.floor(diff / minute);
		diff -= dminute * minute;
		var dsecond = Math.floor(diff / second);
		diff -= dsecond * second;

		var timeStringKorean = "";
		  timeStringKorean = time.getFullYear() + "년 ";
		  timeStringKorean += (time.getMonth() + 1) + "월 ";
		  timeStringKorean += time.getDate() + "일 " + dayName[time.getDay()] + " ";
		  var timeTimeStringKorean = "";
		  if (time.getHours() < 12)
		  {
			timeTimeStringKorean += "오전 ";
			if (time.getHours() == 0)
			  timeTimeStringKorean += "12:";
			else if (time.getHours() < 10)
			  timeTimeStringKorean += "0" + time.getHours() + ":";
			else
			  timeTimeStringKorean += time.getHours() + ":"
		  }
		  else
		  {
			timeTimeStringKorean += "오후 ";
			if (time.getHours() == 12)
			  timeTimeStringKorean += "12:";
			else if (time.getHours() < 22)
			  timeTimeStringKorean += "0" + (time.getHours() - 12) + ":";
			else
			  timeTimeStringKorean += (time.getHours() - 12) + ":";
		  }
		  if (time.getMinutes() >= 10)
			timeTimeStringKorean += time.getMinutes();
		  else
			timeTimeStringKorean += "0" + time.getMinutes();
		  timeTimeStringKorean += ":"
		  if (time.getSeconds() >= 10)
			timeTimeStringKorean += time.getSeconds();
		  else
			timeTimeStringKorean += "0" + time.getSeconds();
		timeStringKorean += timeTimeStringKorean;

		var timestring;
		if (time.toDateString() != now.toDateString())
		{
		  now.setHours(0);
		  now.setMinutes(0);
		  now.setSeconds(0);
		  diff = now - time;
		  var dday = Math.ceil(diff / day);
		  if (dday == 1)
			timestring = "어제 " + timeTimeStringKorean.replace(/:..$/, '');
		  else if (now.getDay() - dday >= 1 && dday <= 3)
		  {
			timestring = dayName[time.getDay()] + " " + timeTimeStringKorean.replace(/:..$/, '');
		  }
		  else
		  {
			if (time.getYear() < now.getYear())
			  timestring = timeStringKorean.replace(/일 .+일/, '일').replace(/:..$/, ''); 
			else
			  timestring = timeStringKorean.replace(/.+년 /, '').replace(/일 .+일/, '일').replace(/:..$/, '');
		  }
		}
		else if (dhour > 1)
		  timestring = dhour + "시간 전";
		else if (dhour == 1)
		  timestring = "약 1시간 전";
		else if (dminute > 1)
		  timestring = dminute + "분 전";
		else if (dminute == 1)
		  timestring = "약 1분 전";
		else if (dsecond > 0)
		  timestring = dsecond + "초 전";

		return timestring;

		};
		function getDateStr(y,m,d,h,min,s) {
		  var res = new Date(y, m-1, d, h, min, s);
//		  alert(m);
		  //alert(h + ' ' + min + ' ' + s);
//		  var d = new Date(date_string);

//		alert(res);
			return getTimestring(res);
		}
		var d = new Date(2011, 07, 22, 00, 11);

	</script>	
</head>

 <body>
	<div id='wrapper'>
		<?
        include "top_menu.php";
        ?>
		
		<div id='left_bg'>
		</div>


		<div id='title'>
			<div id='title_margin_top'><span></span></div>
			<div style='width:195px;height:29px;float:left;'></div>
			<div style='width:41px;height:29px;float:left;'><img src="./img/top_icon_input.png"></div><div style='height:29px;float:left;margin-top:3px;'><span id='article_content' >총 -명의 이웃 소식을 받아보고 있습니다.</span></div>
		</div>
		
		<?
		$current_file = basename(__FILE__);
		include 'side_menu_manage.php';
		?>

		<div id='middle_bg'>
		</div>

		<div id='document_content' style="width:776px;float:left;">
			<div style='height:2px;width:100%;background:#cccccc;float:left;'><span><span></div>
			<div style='height:3px;width:100%;float:left;'><span><span></div>

			<div style="width:714px;background:#F2F2F2;float:left;border:1px solid #E9E9E9;padding:30px;">
				


				<div style="width:30px;height:30px;float:left;"></div>
				<div style="width:600px;float:left;">
					이웃 목록<br>
					<div style="width:100%;height:5px;float:left;"><span></span></div>
				</div>

				<div style="width:100%;height:15px;float:left;"><span></span></div>

				<div style="width:100%;height:1px;background:gray;float:left;"><span></span></div>
				<div style="width:100%;height:2px;background:#ffffff;float:left;"><span></span></div>

				<div style="width:100%;height:15px;float:left;"><span></span></div>
				<br/>



				<!-- 친구 리스트 출력 시작 -->

				<?
					$sql ="
						SELECT A.friend_idx, A.friend_user_idx, B.nickname FROM ndd_friends A, ndd_user B WHERE A.user_idx = '$user_idx' AND A.friend_user_idx = B.user_idx;
					";
					$result = mysql_query($sql,$connect);
					while($row = mysql_fetch_row($result))
					{
						$friend_idx = $row[0];
						$friend_user_idx = $row[1];
						$friend_user_nickname = $row[2];

				?>


					<div style="width:100%;float:left;">
						<div style="width:30px;height:80px;float:left;"></div>
						<!-- 친구 프로필 출력 시작 -->


						<div style='width:73px;height:85px;float:left;'>
						<?
							$user_img = "./upload/member_photo/".$friend_user_idx;

							if(file_exists($user_img)){
						?>
							<img src="<? echo $user_img; ?>" width="73px" height="73px" border=0>
						<?
							}
							else
							{
						?>
						<?
							}
						?>	
						</div>



						<div style='width:15px;height:85px;float:left;'>
						</div>

						<div style='width:150px;height:85px;float:left;'>
							<span id='list_id'><? echo $friend_user_nickname;?><br></span>
							<span id='list_id_detail'>



						<? 
						
							$sql_2="
								SELECT birthday, sex FROM ndd_user_expand WHERE user_idx = $friend_user_idx LIMIT 1;
							";
									
							$result_2 = mysql_query($sql_2,$connect);
				
							$row2 = mysql_fetch_row($result_2);

							if($row2[1]=="M")
								echo "남";
							else if($row[1]=="F")
								echo "여";
							else 
								echo "(미입력)";
							
							echo " / ";

							if($row[0]!="0000-00-00" && $row2[0]!="")
							{

								//생일 입력
								$myBirthDate    = strtotime($row2[0]);

								//만나이
								$birthDate1     = date( 'Ymd', $myBirthDate );
								$nowDate1       = date('Ymd');
								$age1           = floor(($nowDate1 - $birthDate1) / 10000);

								//한국 나이
								$birthDate2     = date( 'Y', $myBirthDate );
								$nowDate2       = date('Y');
								$age2           = $nowDate2 - $birthDate2 + 1 ;

								echo $age2."세";
							}
							else
							{
								echo "(미입력)";

							}
				
						?>				
							<br>
							류마점수 3점<br>
							회원등급 2급 ★★
							</span>

						</div>


						<!-- 친구 프로필 출력 끝 -->


						<!-- 최신 약,정보 기록 출력 시작 -->

						<div style='width:333px;height:85px;float:left;'>

<?

							$sql3="
								SELECT A.cure_idx, A.description, A.reg_timestamp
								FROM ndd_cure A
								WHERE A.user_idx = $friend_user_idx
								
								ORDER BY A.reg_timestamp DESC LIMIT 1;
							";
							$result3 = mysql_query($sql3,$connect);
							$row3 = mysql_fetch_row($result3);

							$cure_idx = $row3[0];
							$cure_date = $row3[2];
							$cure_desc = $row3[1];

?>

							<div style='height:54px;width:310px;float:left;'>
								<span id='list_article_content'><? echo $cure_desc; //제목?> <br></span>

							</div>
							<div style='height:30px;width:310px;float:left;'>
								<span id='list_article_title'>
									<span id="date_<? echo $cure_idx;?>">
									</span>
									<script>
										$('#date_<? echo $cure_idx;?>').text( getDateStr(<? echo substr($cure_date,0,4); ?>, <? echo substr($cure_date,5,2); ?>, <? echo substr($cure_date,8,2); ?>, <? echo substr($cure_date,11,2); ?>, <? echo substr($cure_date,14,2); ?>, <? echo substr($cure_date,17,2); ?>) );
									</script>
								</span>
							</div>

						</div>

						<!-- 최신 약,정보 기록 출력 끝 -->

						<div style='width:80px;padding-top:20px;float:right;'>
							<a href='friends_del.php?friend_idx=<? echo $friend_idx; ?>'><img src='./img/button_friend_del.png' alt='친구끊기' border="0"></a>
						</div>

					</div>

					<div style="width:100%;height:5px;float:left;"><span></span></div>

					<div style="width:100%;height:1px;background:gray;float:left;"><span></span></div>
					<div style="width:100%;height:2px;background:#ffffff;float:left;"><span></span></div>

					<div style="width:100%;height:5px;float:left;"><span></span></div>
					<br/>

				<?
					}
				?>


	
	
					
				


				<!-- 친구 리스트 출력 끝 -->




				
				
				<div style='width:100%;height:30px;float:left;'>
						<a  onclick="" style="cursor:pointer"><img src='./img/button_friend_del_all.png' border="0"></a>
						
				</div>
				
				
			
			</div>
			<? include "footer.php";?>
		</div>

		


	</div>
 </body>
</html>
